package cn.edu.scau.cmi.tancuier.client;

import cn.edu.scau.cmi.tancuier.simpleFactory.MeatFactory;
import cn.edu.scau.cmi.tancuier.simpleFactory.domain.Meat;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleGroup;

public class SimpleFactoryClient extends Application{
	
	@Override
	public void start(Stage primaryStage) throws Exception {
		primaryStage.setTitle("Simple Factory");
		
		FlowPane flowPane = new FlowPane();
		flowPane.setPadding(new Insets(10, 20, 10, 20));
		flowPane.setHgap(5);
		flowPane.setVgap(5);
		
		Label guide = new Label("Please choose the meat that you want to produce: ");
		flowPane.getChildren().add(guide);
		
		ToggleGroup group = new ToggleGroup();
		RadioButton beef = new RadioButton("Beef");
		beef.setToggleGroup(group);
		beef.setUserData("Beef");
		beef.setSelected(true);
		RadioButton pork = new RadioButton("Pork");
		pork.setToggleGroup(group);
		pork.setUserData("Pork");
		RadioButton chicken = new RadioButton("Chicken");
		chicken.setToggleGroup(group);
		chicken.setUserData("Chicken");
		flowPane.getChildren().add(beef);
		flowPane.getChildren().add(pork);
		flowPane.getChildren().add(chicken);
		
		Button produce = new Button("Produce");
		produce.setOnAction(e->{
			String type = group.getSelectedToggle().getUserData().toString();
			Meat meat = MeatFactory.getMeat(type);
			Label label = new Label(meat.produce1()+ "                                    ");
			flowPane.getChildren().add(label);
		});
		flowPane.getChildren().add(produce);
		
		
		Scene scene = new Scene(flowPane, 600, 300);
		primaryStage.setScene(scene);
		primaryStage.show();
	}

	public static void main(String[] args) {
		Application.launch(args);
	}
	
}
